package controllers

import (
	"github.com/3xxx/engineercms/models"
)

// require login controller
type RequireLoginController struct {
	BaseController
	user    models.User //当前用户信息
	isLogin bool
}

func (c *RequireLoginController) Prepare() {
	//从Session里获取数据 设置用户信息
	c.adapterUserInfo()
}

//从session里取用户信息
func (this *RequireLoginController) adapterUserInfo() {
	a := this.GetSession("backenduser")
	if a != nil {
		this.isLogin = true
		this.user = a.(models.User)
		this.Data["backenduser"] = a
	} else {
		this.isLogin = false
		this.Ctx.Output.SetStatus(410)
		this.ReturnJSON(-2, "请登录！", nil)
		this.StopRun()
	}
}
